package cn.itrip.biz.controller;

import cn.itrip.beans.dto.Dto;
import cn.itrip.beans.pojo.ItripAreaDic;
import cn.itrip.beans.pojo.ItripHotel;
import cn.itrip.beans.vo.ItripLabelDicVO;
import cn.itrip.beans.vo.hotel.HotelVideoDescVO;
import cn.itrip.beans.vo.hotel.ItripSearchFacilitiesHotelVO;
import cn.itrip.common.DtoUtil;
import cn.itrip.common.EmptyUtils;
import cn.itrip.common.ErrorCode;
import cn.itrip.dao.service.ItripHotelService;
import cn.itrip.dao.service.ItripLabelService;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.relational.repository.query.DtoInstantiatingConverter;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Tequila
 **/
@RestController
@RequestMapping("/biz/api/hotel")
@CrossOrigin
public class ItripHotelController {

    @Autowired
    private ItripHotelService itripHotelService;
    @Autowired
    private ItripLabelService itripLabelService;

    @GetMapping("/getvideodesc/{hotelId}")
    public Dto getVideoDesc(@PathVariable Integer hotelId){
        try {
            if (EmptyUtils.isNotEmpty(hotelId)){
                // 1.查询酒店名称
                ItripHotel itripHotel = itripHotelService.queryHotelById(hotelId);
                // 2.查询商圈列表
                List<ItripAreaDic> itripAreaDicList = itripHotelService.queryTradingAreaNameList(hotelId);
                // 3.酒店特色列表
                List<ItripLabelDicVO> voList = itripLabelService.queryHotelDetails(hotelId);
                // 创建返回到前端的vo对象
                HotelVideoDescVO vo = new HotelVideoDescVO();
                vo.setHotelName(itripHotel.getHotelname());// 赋值
                List<String> featureNameList = new ArrayList<>();  // 只获取对应的字段
                List<String> AreaNameList = new ArrayList<>();
                // 将特色名称存入列表中
                for (ItripLabelDicVO itripLabelDicVO : voList) {
                    featureNameList.add(itripLabelDicVO.getName());
                }
                // 将商圈名称存入列表中
                for (ItripAreaDic itripAreaDic : itripAreaDicList) {
                    AreaNameList.add(itripAreaDic.getName());
                }
                // 存入vo
                vo.setHotelFeatureList(featureNameList);
                vo.setTradingAreaNameList(AreaNameList);
                return DtoUtil.returnDataSuccess(vo);
            }else{
                return DtoUtil.returnFail("酒店id不能为空",ErrorCode.PARAM_ISNULL);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统错误",ErrorCode.SYSTEM_ERROR);
        }
    }

    @GetMapping("/queryhotelfacilities/{hotelId}")
    public Dto queryHotelFacilities(@PathVariable Integer hotelId){
        try {
            if (EmptyUtils.isNotEmpty(hotelId)){
               ItripHotel itripHotel = itripHotelService.queryHotelById(hotelId);
               return DtoUtil.returnDataSuccess(itripHotel.getFacilities());
            }else{
                return DtoUtil.returnFail("酒店id不能为空!", ErrorCode.PARAM_ISNULL);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常",ErrorCode.SYSTEM_ERROR);
        }
    }
    @GetMapping("//queryhotelpolicy/{hotelId}")
    public Dto queryHotelPolicy(@PathVariable Integer hotelId){
        try {
            if (EmptyUtils.isNotEmpty(hotelId)){
               ItripHotel itripHotel = itripHotelService.queryHotelById(hotelId);
               return DtoUtil.returnDataSuccess(itripHotel.getHotelpolicy());
            }else{
                return DtoUtil.returnFail("酒店id不能为空!", ErrorCode.PARAM_ISNULL);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常",ErrorCode.SYSTEM_ERROR);
        }
    }

}
